function getSearchArticle(num) {
    const blogs = $('#index_blog');
    let href = root + '/article/search/' + num + '?search=' + searchText
    $.get(href, function(data) {
        blogs.html('')
        data.data.list.forEach(el => {
            blogs.prepend(assemblySearchMsg(el.articleId, el.articleTitle, el.articleContext))
        })
        pageSearchIndex(data.data)
    })
}

function assemblySearchMsg(id, title, text) {
    // <i><a href="/"><img src="images/1.jpg"></a></i>
    const href = 'infopic.html'
    const msg = '<li>'
        + '<h3><a href="' + href + '?id=' + id + '" target=_blank>' + title + '</a></h3>'
        + '<p>' + text + '</p>'
        + '</li>'
    return msg
}

function pageSearchIndex(pageInfo) {
    const indexs = $('#pagelist')
    let str = ''
    if (pageInfo.hasPreviousPage) {
        str = str
            + '<a href="#" onclick="Searchpage(' + pageInfo.prePage + ',' + searchText + ')" ><b>&lt;&lt;</b></a>'
            + '&nbsp;&nbsp;'
    }
    for (var i = 1; i <= pageInfo.lastPage; i++) {
        str = str + '<a href="#"'
        if (i === pageInfo.pageNum) {
            str = str + 'class=" curPage" '
        } else {
            str = str + 'onclick="Searchpage(' + i + ',' + searchText +  ')" '
        }
        str = str + '>' + i + '</a>'
            + '&nbsp;&nbsp;'
    }
    if (pageInfo.hasNextPage) {
        str = str + '<a href="#" onclick="Searchpage(' + pageInfo.nextPage + ',' + searchText +  ')">&gt;&gt;</a>'
    }
    indexs.html('')
    indexs.append(str)
}

function Searchpage(num) {
    getSearchArticle(num)
}

const url = document.URL
const val = url.split('?')[1]
let searchText = val.split('=')[1]
if (searchText === '#' || !searchText) {
    searchText = ''
}
getSearchArticle(1)